<?php
namespace app\common\model;
use think\Model;

class Category extends Model{
    /**
     * @var bool 设置自动填充时间
     */
    protected $autoWriteTimestamp=true;
    public $list_rows;
    public function initialize(){
        //获取配置项的分页数
        $this->list_rows=config('paginate.list_rows');
    }

    /**
     * @param $data 添加的数据
     * @return false|int
     */
    public function add($data){
        $data['status']=1;
        return $this->save($data);
    }
    public function updateById($data,$id){
        return $this->save($data,['id'=>$id]);
    }
    /**
     * @return 得到一级栏目
     */

    public function getNormalFirstCategory(){
        $where=[
            'parent_id'=>0,
            'status'=>['<>',0]
        ];
        $order=[
            'listorder'=>'desc',
            'id'=>'desc'
        ];
        return $this->where($where)->order($order)->select();
    }

    public function getCategory($parentId=0,$name=null,$status=null){
        $where=[
            'parent_id'=>$parentId,
            'status'=>['<>',0],
        ];
        if(!empty($name)){
            $where['name']=['like','%'.$name.'%'];
        }
        if(!empty($status)){
            $where['status']=$status;
        }
        $order=[
            'listorder'=>'desc',
            'id'=>'desc'
        ];

        return $this->where($where)->order($order)->paginate();


    }




}